home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Performance Co-Pilot 1.3
/
SGI Performance Co-Pilot 1.3.iso
/
dist
/
dist6.3
/
pcp.idb
/
usr
/
sbin
/
pmafm.z
/
pmafm
Wrap
Text File
|
1997-04-03
|
11KB
|
536 lines
#!/bin/sh
#
# Copyright 1995, Silicon Graphics, Inc.
# ALL RIGHTS RESERVED
#
# UNPUBLISHED -- Rights reserved under the copyright laws of the United
# States. Use of a copyright notice is precautionary only and does not
# imply publication or disclosure.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
# Use, duplication or disclosure by the Government is subject to restrictions
# as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
# in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
# in similar or successor clauses in the FAR, or the DOD or NASA FAR
# Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
# 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
#
# THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
# INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
# DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
# PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
# GRAPHICS, INC.
#
# $Id: pmafm,v 2.2 1997/03/21 08:54:55 kenmcd Exp $
_usage()
{
echo "Usage: pmafm folioname [command [arg ...]]"
}
_help()
{
echo 'PCP Archive Folio Manager
Commands:
archives - select all archives
archives N[,...] - select archives with these ordinal numbers
archives name[,...] - select archives with these names
check - integrity check for folio
help - this message
hosts - select archives for all hosts (the default)
hosts hostname[,...] - select archives for just these hosts
list [verbose] - display folio contents
quit - exit
remove - echo the sh(1) command to delete all files
associated with the folio
repeat tool [arg ...] - execute a known PCP tool on each archive in turn
replay - replay archives using the tool that created the folio
[run] tool [arg ...] - execute a known PCP tool on the selected archives
selections - list selected archives
Selection:
If specified, both the "archives" and the "hosts" selection criteria
are applied as a conjunction.'
}
if [ $# -lt 1 ]
then
_usage
exit 1
fi
if [ ! -f $1 ]
then
if [ "X$1" = "X-?" ]
then
_usage
echo
_help
else
echo "pmafm: cannot open folio \"$1\""
fi
exit 1
fi
_FOLIOPATH=`dirname $1`
if [ "$_FOLIOPATH" = "." ]
then
_FOLIOPATH=""
elif [ -d $_FOLIOPATH ]
then
_TMP=`pwd`
cd $_FOLIOPATH
_FOLIOPATH=`pwd`/
cd $_TMP
fi
_FOLIO="$1"
_FOLIONAME=`basename $_FOLIO`
#
# TODO ... when /etc/magic is safe, use file(1)
if grep '^PCPFolio' $1 >/dev/null && grep '^Version:' $1 >/dev/null
then
:
else
echo "pmafm: \"${_FOLIOPATH}$_FOLIONAME\" is not in PCP archive folio format"
exit 1
fi
_HOSTS=""
_ALL_HOSTS=`nawk <$_FOLIO '$1 == "Archive:" { printf " %s",$2 }'; echo | sort -u`
_ARCHIVES=""
_ALL_ARCHIVES=`nawk <$_FOLIO '$1 == "Archive:" { printf " %s",$3 }'; echo`
_DEBUG=false
export _DEBUG _FOLIO _HOSTS _ALL_HOSTS _ARCHIVES _ALL_ARCHIVES
_SINGLE=""
_MULTI=""
_REPLAY=""
# collect names of known tools, and "run" scripts for each
#
for config in /var/pcp/config/pmafm/*
do
if [ "$config" = '/var/pcp/config/pmafm/*' ]
then
echo "pmafm: Warning: no PCP tool configurations in /var/pcp/config/pmafm/"
else
SINGLE=""
MULTI=""
REPLAY=""
. $config
[ ! -z "$SINGLE" ] && _SINGLE="$_SINGLE $SINGLE"
[ ! -z "$MULTI" ] && _MULTI="$_MULTI $MULTI"
[ ! -z "$REPLAY" ] && _REPLAY="$_REPLAY $REPLAY"
fi
done
tmp=/tmp/$$
trap "rm -f $tmp; exit" 0 1 2 3 15
_check_file()
{
if [ ! -f "$1" ]
then
echo "No such file: $1" >>$tmp
else
dd ibs=1 count=7 if="$1" 2>/dev/null | od -X | nawk '
NR == 1 && $2 == "00000084" && $3 == "50052600" { exit 0 }
{ exit 1 }'
if [ $? -eq 0 ]
then
:
else
echo "Not a PCP archive file: $1" >>$tmp
fi
fi
}
_check()
{
sed -n '/^Archive:/p' <$_FOLIO \
| while read xxx host arch
do
rm -f $tmp
path=`_fix_arch_path "" $arch`
echo "Archive: $path ... \c"
_check_file $path.index
_check_file $path.meta
_check_file $path.0
if [ ! -s $tmp ]
then
realhost=`pmdumplog -l $path | sed -n -e '/^Performance metrics/s/.* host //p'`
[ "X$host" != "X$realhost" ] && \
echo "Hostname mismatch: folio=$host archive=$realhost" >>$tmp
fi
if [ -s $tmp ]
then
echo "Errors"
sed -e 's/^/ /' $tmp
else
echo "OK"
fi
done
}
_dir()
{
echo
echo "PCP Archive Folio: $_FOLIONAME"
[ ! -z "$_FOLIOPATH" ] && echo "Folio Directory: $_FOLIOPATH"
nawk <$_FOLIO '
$1 == "Created:" { print; next }
$1 == "Creator:" { print; next }'
echo
echo "Ordinal Hostname Archive Basename"
i=1
sed -n '/^Archive:/p' $_FOLIO \
| while read xxx host archive
do
printf " [%3s] %-20s %s\n" $i $host $archive
[ "X$1" = "Xverbose" ] && pmdumplog -l `_fix_arch_path "" $archive` | sed -e 's/^/ /'
i=`expr $i + 1`
done
}
# $1 is separater
#
_fix_arch_path()
{
sep="$1"
shift
archlist=""
for arch
do
if [ ! -z "$_FOLIOPATH" ]
then
case $arch
in
/*)
;;
*)
arch=${_FOLIOPATH}$arch
;;
esac
fi
if [ -z "$archlist" ]
then
archlist="${arch}"
else
archlist="${archlist}${sep}${arch}"
fi
done
echo $archlist
}
_get_archlist()
{
if [ -z "$_ARCHIVES" ]
then
archlist="$_ALL_ARCHIVES"
else
archlist="$_ARCHIVES"
fi
if [ ! -z "$_HOSTS" ]
then
newlist=""
for arch in $archlist
do
host=`nawk <$_FOLIO '$3 == "'$arch'" { print $2; exit }'`
if echo "$_HOSTS " | grep " $host " >/dev/null
then
newlist="$newlist $arch"
fi
done
archlist=$newlist
fi
echo $archlist
}
_replay()
{
_CREATOR=""
_REPLAY_CONFIG=""
eval `sed -n <$_FOLIO -e '/^Creator:/{
s/Creator:[ ]*//
s/^/_CREATOR=/
s/[ ][ ]*/ _REPLAY_CONFIG=/
p
}'`
if [ -z "$_CREATOR" ]
then
echo "Error: cannot determine folio creator"
return
else
if [ ! -z "$_REPLAY_CONFIG" ]
then
_REPLAY_CONFIG=`_fix_arch_path "" "$_REPLAY_CONFIG"`
echo "Configuration File: $_REPLAY_CONFIG"
if [ ! -f "$_REPLAY_CONFIG" ]
then
echo "Error: cannot find Configuration File"
return
fi
fi
fi
if echo "$_REPLAY " | grep " $_CREATOR " >/dev/null
then
_run $_CREATOR -c $_REPLAY_CONFIG
else
echo "Error: I don't know how to replay a folio created by \"$_CREATOR\""
echo " ... choose a PCP tool and use the \"run\" command to replay"
fi
}
_known()
{
echo "Known PCP tools:"
echo "$_SINGLE$_MULTI" \
| sed -e 's/^ *//' \
| tr ' ' '\012' \
| sort \
| fmt \
| sed -e 's/^/ /'
}
_run()
{
tool=$1
shift
archlist=`_get_archlist`
if [ -z "$archlist" ]
then
echo "Error: no selected archives"
return
fi
if $_REPEAT || ( echo "$_SINGLE " | grep " $tool " >/dev/null )
then
n_arch=`echo $archlist | wc -w | sed -e 's/ *//g'`
[ "$n_arch" -gt 1 ] && echo "Note: running $tool serially, once per archive"
for arch in $archlist
do
nawk <$_FOLIO '$3 == "'$arch'" { printf "Host: %s",$2; exit }'
path=`_fix_arch_path "" "$arch"`
echo " Archive: $path"
# arrgh ... special case for pmdumplog where -a is something else
# and archive comes last ... sigh
#
case $tool
in
*pmdumplog*)
$tool $* $path
;;
*)
$tool -a $path $*
;;
esac
done
elif echo "$_MULTI " | grep " $tool " >/dev/null
then
$tool -a `_fix_arch_path "," $archlist` $*
elif [ "X$tool" = "X_show_me_" ]
then
for arch in $archlist
do
path=`_fix_arch_path "" "$arch"`
echo "Archive: $path"
done
else
echo "Sorry, don't know how to run \"$tool\" ..."
fi
}
_MORE=true
while $_MORE
do
if [ $# -gt 1 ]
then
shift
cmd="$1"
shift
args=$*
_MORE=false
else
echo "pmafm> \c"
read cmd args
if [ $? -ne 0 ]
then
echo
break
elif [ -z "$cmd" ]
then
continue
fi
fi
_REPEAT=false
if echo "$_SINGLE $_MULTI " | grep " $cmd " >/dev/null
then
# recognized command
_run $cmd $args
else
case $cmd
in
a|ar|arch|archi|archiv|archive|archives)
case $args
in
'')
_ARCHIVES=""
;;
*)
_ARCHIVES=""
for arch in `echo $args | sed -e 's/,/ /g'`
do
_TMP=`nawk <$_FOLIO '
$1 == "Archive:" { if ("'$arch'" == $3) {
print $3
exit
}
i++
if ("'$arch'" == i) {
print $3
exit
}
}'`
if [ -z "$_TMP" ]
then
echo "Warning: archive \"$arch\" not in folio ... ignored"
else
_ARCHIVES="$_ARCHIVES $_TMP"
fi
done
;;
esac
;;
c|ch|che|chec|check)
_check
;;
d|de|deb|debu|debug)
if $_DEBUG
then
_DEBUG=false
set -
else
_DEBUG=true
set -x
fi
;;
\?|he|hel|help)
_help
;;
ho|hos|host|hosts)
case $args
in
'')
_HOSTS=""
;;
*)
_HOSTS=""
for host in `echo $args | sed -e 's/,/ /g'`
do
if echo "$_ALL_HOSTS " | grep " $host " >/dev/null
then
_HOSTS="$_HOSTS $host"
else
echo "Warning: host \"$host\" not in folio ... ignored"
fi
done
;;
esac
;;
l|li|lis|list)
case $args
in
v|ve|ver|verb|verbo|verbos|verbose)
_dir verbose
;;
'')
_dir
;;
*)
echo "Illegal option \"$args\" ... ignored"
_dir
;;
esac
[ ! -z "$_HOSTS" ] && echo "Host Selections:$_HOSTS"
[ ! -z "$_ARCHIVES" ] && echo "Archive Selections:$_ARCHIVES"
;;
q|qu|qui|quit)
break
;;
ru|run|repe|repea|repeat)
case $cmd
in
repe|repea|repeat)
_REPEAT=true
;;
esac
tool=`echo "$args" | sed -e 's/ .*//'`
if [ -z "$tool" ]
then
echo "Error: missing PCP tool name"
_known
elif [ "X$tool" = 'X?' ]
then
_known
elif echo "$_SINGLE $_MULTI " | grep " $tool " >/dev/null
then
_run $args
else
echo "Error: Unknown PCP tool: $tool"
_known
fi
;;
rem|remo|remov|remove)
[ ! -z "$_FOLIOPATH" ] && echo "( cd $_FOLIOPATH; \c"
echo "rm -f $_FOLIONAME\c"
nawk <$_FOLIO '$1 == "Creator:" && NF > 2 { printf " %s",$3; exit }'
for arch in $_ALL_ARCHIVES
do
echo " $arch.meta $arch.index\c"
path=`_fix_arch_path "" $arch`
pmdumplog -t $path 2>/dev/null \
| nawk '/^[0-9][0-9]:/ { print $2 }' \
| sort -u \
| while read vol
do
echo " $arch.$vol\c"
done
done
[ ! -z "$_FOLIOPATH" ] && echo " )\c"
echo
;;
repl|repla|replay)
_replay
;;
s|se|sel|sele|selec|select|selecti|selectio|selection|selections)
_run _show_me_
;;
*)
echo "Unknown command \"$cmd\" ... enter \"help\" for more information"
;;
esac
fi
done